import UIKit
import Flutter

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
    let controller : FlutterViewController = window?.rootViewController as! FlutterViewController
    let channel = FlutterMethodChannel(name: "toast_plugin", binaryMessenger: controller.binaryMessenger)
    channel.setMethodCallHandler { (call: FlutterMethodCall, result: @escaping FlutterResult) in
      if call.method == "toast" {
          // 检查是否有参数
          if let arguments = call.arguments as? [String: Any] {
              // 获取具名参数
              if let message = arguments["message"] as? String {
                  print("参数 message 的值: \(message)")
              }
              result("方法调用成功")
          } else {
              result(FlutterError(code: "INVALID_ARGUMENTS", message: "参数格式不正确", details: nil))
          }
      } else {
        result(FlutterMethodNotImplemented)
      }
    }
      GeneratedPluginRegistrant.register(with: self)
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }
}
